package com.bauer.framework.autumn.web;

import com.bauer.framework.autumn.WebStartPoint;
import com.bauer.framework.autumn.context.AppContext;
import com.bauer.framework.autumn.utils.HttpUtils;
import com.bauer.framework.autumn.web.mapping.AnnotationMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * @Author ：rui.wei
 * @Date ：Created in 8:57 2018/7/30
 * @Description：
 */
public class Dispatcher extends HttpServlet {

    private AnnotationMapping annotationMapping=  new AnnotationMapping();

    @Override
    public void init() throws ServletException {
        AppContext appContext = (AppContext) getServletContext().getAttribute(WebStartPoint.APP_CONTEXT_ROOT);
        annotationMapping.initMapping(appContext);
    }


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doDispatch(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doDispatch(req, resp);
    }

    @Override
    protected void doPut(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doDispatch(req, resp);
    }

    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doDispatch(req, resp);
    }

    private void doDispatch(HttpServletRequest req, HttpServletResponse resp){
        String method  = HttpUtils.getMethod(req);
        String url = HttpUtils.getPath(req);


    }

}
